package com.itheima.tanhua.controller;

import com.itheima.tanhua.dto.RecommendUserDto;
import com.itheima.tanhua.service.TanHuaService;
import com.itheima.tanhua.vo.NearUserVo;
import com.itheima.tanhua.vo.PageResult;
import com.itheima.tanhua.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Lff
 * @date 2022/3/25
 */
@RestController
@RequestMapping("/tanhua")
public class TanHuaController {
    @Autowired
    private TanHuaService tanHuaService;

    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest userInfo = tanHuaService.getTodayBest();
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 分页查询推荐好友列表
     *
     * @param recommendUserDto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto) {
        //调用服务
        PageResult pageResult = tanHuaService.getRecommendUsers(recommendUserDto);
        ///返回数据集
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 获取佳人信息
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long id) {
        TodayBest result = tanHuaService.getPersonalInfo(id);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(String userId) {
        //参数类型转换
        Long userId1 = Long.valueOf(userId);
        String strangerQuestions = tanHuaService.getStrangerQuestionsById(userId1);
        return ResponseEntity.ok(strangerQuestions);
    }


    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map) {
        //参数类型转换
        Long userId = Long.valueOf(map.get("userId").toString());
        String reply = map.get("reply").toString();

        tanHuaService.replyStrangerQuestions(userId, reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-左滑右滑
     */
    @GetMapping("/cards")
    public ResponseEntity getCards() {
        //调用服务获取推荐用户列表
        List<TodayBest> list = tanHuaService.findCardsToTodayBest();
        return ResponseEntity.ok(list);
    }

    /**
     * 探花-喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity toLove(@PathVariable Long id) {
        tanHuaService.toLove(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-不喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity toUnLove(@PathVariable Long id) {
        tanHuaService.toUnLove(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜索附近的人
     * distance 单位 m
     * 默认是2000m
     */
    @GetMapping("/search")
    public ResponseEntity search(@RequestParam(defaultValue = "2000") Double distance,
                                 @RequestParam(required = true) String gender) {
        List<NearUserVo> nearUsers = tanHuaService.searchNear(gender, distance);
        return ResponseEntity.ok(nearUsers);
    }
}
